<?php
class Merchant_Model_TakeStock
{

	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new Merchant_Model_DbTable_TakeStock();
	}
	
	/**
	*add DB Adapter
	*/
	public function getAdapter(){
		return $this->_table->getAdapter();
	}
	
    public function getByCond($condition=array(),$type='*',$pageSize=0,$page=1,$orderby=array()){
        $select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table,$type);
        $select->where("1 =?",1);
		if(isset($condition['ts_code']) && $condition['ts_code']!=''){
            $select->where('ts_code=?', $condition['ts_code']);
        }
        if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }else{
            $select->order($orderby);
            if($pageSize>0 and $page>0){
                $start =($page-1)*$pageSize;
                $select->limit($pageSize,$start);
            }
			$sql=$select->__toString();
		    return $this->_table->getAdapter()->fetchAll($sql);
        }		
	}
	
	public function getByfield($field,$value){
		$where = $this->_table->getAdapter()->quoteInto("{$field} = ?",$value);	
		return $this->_table->fetchRow($where);
	}


	
}